package com.project.webservice.controller;

import com.project.dto.R;
import com.project.webservice.dto.TUserDto;
import com.project.webservice.entity.JkXlxxMid;
import com.project.webservice.entity.TUser;
import com.project.webservice.service.TUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/WS_RFID_FULL_TEST")
public class WsRfidFullTestController {

    @Resource
    private TUserService tUserService;
    /**
     * 插入用户表
     * @param tUserDto
     * @return
     */
    @PostMapping("/WS_RFID.asmx/AddUser")
    public R saveJkXlxxMid(@RequestBody TUserDto tUserDto){
        TUser user = new TUser();
        user.setUid(tUserDto.getUid());
        user.setUserName(tUserDto.getUsername());
        user.setUserType(StringUtils.isNotBlank(tUserDto.getUserType())?Integer.parseInt(tUserDto.getUserType()):null);
        user.setPwd(tUserDto.getPwd());
        user.setIsRole(StringUtils.isNotBlank(tUserDto.getIsRole())?Boolean.parseBoolean(tUserDto.getIsRole()):null);
        user.setRole(tUserDto.getRole());
        user.setIsAdmin(false);
        boolean isSave = tUserService.save(user);
        return isSave ? R.success() :R.fail("插入失败");
    }
}
